/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DiracInputDialog.java
 *
 * Created on 2011. 11. 11, �ㅽ� 9:55:04
 */
package cct.dirac;

import cct.interfaces.AtomInterface;
import cct.interfaces.MoleculeInterface;
import cct.modelling.Molecule;

/**
 *
 * @author Hilbert
 */
public class ExportDiracInputDialog extends javax.swing.JDialog {

    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
	private MoleculeInterface moleculeInterface;
	/** Creates new form DiracInputDialog */
    public ExportDiracInputDialog(java.awt.Frame parent, boolean modal, MoleculeInterface moleculeInterface) {
        super(parent, modal);
        if(moleculeInterface == null){
        	throw new IllegalArgumentException("moleculeInterface should be not null");
        }
        
        this.moleculeInterface = moleculeInterface;
        
        initComponents();
        StringBuffer sbGeometry = new StringBuffer();
        for(int i = 0; i < this.moleculeInterface.getNumberOfAtoms(); i++){
        	AtomInterface ai = this.moleculeInterface.getAtomInterface(i);
        	
        	sbGeometry.append(ai.getAtomicNumber())
        			  .append("\t")
        			  .append(ai.getX())
        			  .append("\t")
        			  .append(ai.getY())
        			  .append("\t")
        			  .append(ai.getZ());
        	sbGeometry.append(LINE_SEPARATOR);
        			  
        }
        this.taGeometry.setText(sbGeometry.toString());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblTitle = new javax.swing.JLabel();
        tfTitle = new javax.swing.JTextField();
        lblSymm = new javax.swing.JLabel();
        tfSymm = new javax.swing.JTextField();
        lblGeometry = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taGeometry = new javax.swing.JTextArea();
        lblBasis = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblBasis = new javax.swing.JTable();
        btnOK = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Export Dirac Input File");

        lblTitle.setText("Title");

        lblSymm.setText("Symmetry");

        tfSymm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfSymmActionPerformed(evt);
            }
        });

        lblGeometry.setText("Geometry");

        taGeometry.setColumns(20);
        taGeometry.setRows(5);
        jScrollPane1.setViewportView(taGeometry);

        lblBasis.setText("Basis-set");

        tblBasis.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tblBasis);

        btnOK.setText("OK");
        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKActionPerformed(evt);
            }
        });

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(lblGeometry)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
                            .add(jScrollPane2, 0, 0, Short.MAX_VALUE)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(lblTitle)
                                    .add(lblSymm))
                                .add(23, 23, 23)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(tfSymm)
                                    .add(tfTitle, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)))
                            .add(lblBasis))
                        .addContainerGap())
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(btnOK)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnCancel)
                        .add(181, 181, 181))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblTitle)
                    .add(tfTitle, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblSymm)
                    .add(tfSymm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(17, 17, 17)
                .add(lblGeometry)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(38, 38, 38)
                .add(lblBasis)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnOK)
                    .add(btnCancel))
                .add(32, 32, 32))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void tfSymmActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_tfSymmActionPerformed
	// TODO add your handling code here:
	}// GEN-LAST:event_tfSymmActionPerformed

	private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnOKActionPerformed
		// TODO: Write Dirac Input file
		this.dispose();
	}// GEN-LAST:event_btnOKActionPerformed

	private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnCancelActionPerformed
		this.dispose();
	}// GEN-LAST:event_btnCancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ExportDiracInputDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ExportDiracInputDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ExportDiracInputDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ExportDiracInputDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        final Molecule mol = new Molecule();
        
        mol.addAtom(6, 0, 0, 0);
        mol.addAtom(8, 1, 1, 1);
        mol.addAtom(1, 1, 1, 1);
        mol.addAtom(1, 1, 1, 1);
        
        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
        	
            public void run() {
                ExportDiracInputDialog dialog = new ExportDiracInputDialog(new javax.swing.JFrame(), true, mol);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnOK;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblBasis;
    private javax.swing.JLabel lblGeometry;
    private javax.swing.JLabel lblSymm;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JTextArea taGeometry;
    private javax.swing.JTable tblBasis;
    private javax.swing.JTextField tfSymm;
    private javax.swing.JTextField tfTitle;
    // End of variables declaration//GEN-END:variables
}
